home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / E / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  26.5 KB  |  1,016 lines

  1. /*
  2. **
  3. **    E.generator - Copyright © 1996 Simone Tellini
  4. **                  All Rights Reserved
  5. **
  6. */
  7.  
  8. /// Includes
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. #include <exec/types.h>                 // exec
  12. #include <exec/lists.h>
  13. #include <exec/memory.h>
  14. #include <exec/nodes.h>
  15. #include <dos/dos.h>                    // dos
  16. #include <dos/dostags.h>
  17. #include <intuition/intuition.h>        // intuition
  18. #include <intuition/gadgetclass.h>
  19. #include <graphics/text.h>              // graphics
  20. #include <libraries/gadtools.h>         // libraries
  21. #include <libraries/reqtools.h>
  22. #include <clib/exec_protos.h>           // protos
  23. #include <clib/dos_protos.h>
  24. #include <clib/intuition_protos.h>
  25. #include <clib/reqtools_protos.h>
  26. #include <pragmas/exec_pragmas.h>       // pragmas
  27. #include <pragmas/dos_pragmas.h>
  28. #include <pragmas/intuition_pragmas.h>
  29. #include <pragmas/graphics_pragmas.h>
  30. #include <pragmas/gadtools_pragmas.h>
  31. #include <pragmas/reqtools_pragmas.h>
  32.  
  33. #include <string.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <ctype.h>
  37.  
  38. #include "DEV_IE:Generators/defs.h"
  39. #include "DEV_IE:Include/IEditor.h"
  40.  
  41. #include "Protos.h"
  42. ///
  43. /// Data
  44. ULONG idcmps[] = {
  45.         1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200,
  46.         0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
  47.         0x10000, 0x20000, 0x40000, 0x80000, 0x100000,
  48.         0x200000, 0x400000, 0x800000, 0x1000000,
  49.         0x2000000, 0x4000000
  50.       };
  51.  
  52. ULONG wflgs[] = {
  53.         1, 2, 4, 8, 0x10, 0x20, 0, 0x40, 0x80, 0x100, 0x200,
  54.         0x400, 0x800, 0x1000, 0x10000, 0x20000, 0x40000,
  55.         0x200000
  56.       };
  57.  
  58. UBYTE Header[] =
  59.     "/*\n"
  60.     "    E source code created by Interface Editor\n"
  61.     "    Copyright © 1994-1996 by Simone Tellini\n\n"
  62.     "    The E.generator was wrote with the help of Pietro Altomani\n\n"
  63.     "    Generator:  %s\n"
  64.     "    Copy registered to :  %s\n"
  65.     "    Serial Number      : #%ld\n"
  66.     "*/\n\n";
  67.  
  68. UBYTE   Null[] = "NIL";
  69.  
  70. static UBYTE   ARexxHandleArray[] = "\n"
  71.               "void HandleRexxMsg( void )\n"
  72.               "{\n"
  73.               "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
  74.               "\tWORD\t\tn;\n"
  75.               "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
  76.               "\tstruct RexxMsg\t*RxMsg;\n"
  77.               "\tUBYTE\t\tbuffer[1024], command[256];\n"
  78.               "\tUBYTE\t\t*arguments;\n"
  79.               "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
  80.               "\n"
  81.               "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
  82.               "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
  83.               "\t\t\tif( RxMsg->rm_Args[15] )\n"
  84.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
  85.               "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
  86.               "\t\t\tDeleteRexxMsg( RxMsg );\n"
  87.               "\t\t\tRX_Unconfirmed -= 1;\n"
  88.               "\t\t}\n"
  89.               "\t\telse {\n\n"
  90.               "\t\t\tRxMsg->rm_Result1 = NULL;\n"
  91.               "\t\t\tRxMsg->rm_Result2 = NULL;\n"
  92.               "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
  93.               "\n"
  94.               "\t\t\tn = 0;\n"
  95.               "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
  96.               "\t\t\t\tcommand[n] = buffer[n];\n"
  97.               "\t\t\t\tn++;\n"
  98.               "\t\t\t};\n"
  99.               "\t\t\tcommand[n] = '\\0';\n\n"
  100.               "\t\t\tn = 0;\n"
  101.               "\t\t\twhile( CmdTable[n].command ) {\n"
  102.               "\t\t\t\tif( stricmp( CmdTable[n].command, command ) == 0 ) {\n"
  103.               "\t\t\t\t\tfound = TRUE;\n"
  104.               "\t\t\t\t\tbreak;\n"
  105.               "\t\t\t\t} else\n"
  106.               "\t\t\t\t\tn++;\n"
  107.               "\t\t\t};\n\n"
  108.               "\t\t\tif( found ) {\n"
  109.               "\t\t\t\tif( CmdTable[n].template ) {\n"
  110.               "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
  111.               "\t\t\t\t\t\targuments = buffer + strlen( CmdTable[n].command );\n\n"
  112.               "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
  113.               "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
  114.               "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
  115.               "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
  116.               "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
  117.               "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
  118.               "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
  119.               "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
  120.               "\n"
  121.               "\t\t\t\t\t\tif( rdargs = ReadArgs( CmdTable[n].template, ArgArray, args )) {\n\n"
  122.               "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n"
  123.               "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
  124.               "\t\t\t\t\t\t} else\n"
  125.               "\t\t\t\t\t\t\tfail = TRUE;\n\n"
  126.               "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
  127.               "\t\t\t\t\t} else\n"
  128.               "\t\t\t\t\t\tfail = TRUE;\n\n"
  129.               "\t\t\t\t} else\n"
  130.               "\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n\n"
  131.               "\t\t\t} else {\n\n"
  132.               "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
  133.               "\t\t\t\t\tfail = TRUE;\n\n"
  134.               "\t\t\t};\n\n"
  135.               "\t\t\tif( fail )\n"
  136.               "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
  137.               "\t\t\tif( found )\n"
  138.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
  139.               "\t\t}\n"
  140.               "\t}\n"
  141.               "}\n";
  142.  
  143. static UBYTE   ARexxHandleList[] = "\n"
  144.               "void HandleRexxMsg( void )\n"
  145.               "{\n"
  146.               "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
  147.               "\tWORD\t\tn;\n"
  148.               "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
  149.               "\tstruct RexxMsg\t*RxMsg;\n"
  150.               "\tUBYTE\t\tbuffer[1024], command[256];\n"
  151.               "\tUBYTE\t\t*arguments;\n"
  152.               "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
  153.               "\n"
  154.               "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
  155.               "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
  156.               "\t\t\tif( RxMsg->rm_Args[15] )\n"
  157.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
  158.               "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
  159.               "\t\t\tDeleteRexxMsg( RxMsg );\n"
  160.               "\t\t\tRX_Unconfirmed -= 1;\n"
  161.               "\t\t}\n"
  162.               "\t\telse {\n\n"
  163.               "\t\t\tRxMsg->rm_Result1 = NULL;\n"
  164.               "\t\t\tRxMsg->rm_Result2 = NULL;\n"
  165.               "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
  166.               "\n"
  167.               "\t\t\tn = 0;\n"
  168.               "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
  169.               "\t\t\t\tcommand[n] = buffer[n];\n"
  170.               "\t\t\t\tn++;\n"
  171.               "\t\t\t};\n"
  172.               "\t\t\tcommand[n] = '\\0';\n\n"
  173.               "\t\t\tn = 0;\n"
  174.               "\t\t\tstruct CmdNode *Cmd;\n"
  175.               "\t\t\tfor( Cmd = RexxCommands.mlh_Head; Cmd->Node.ln_Succ; Cmd = Cmd->Node.ln_Succ ) {\n"
  176.               "\t\t\t\tif( stricmp( Cmd->Node.ln_Name, command ) == 0 ) {\n"
  177.               "\t\t\t\t\tfound = TRUE;\n"
  178.               "\t\t\t\t\tbreak;\n"
  179.               "\t\t\t\t}"
  180.               "\t\t\t};\n\n"
  181.               "\t\t\tif( found ) {\n"
  182.               "\t\t\t\tif( Cmd->Template ) {\n"
  183.               "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
  184.               "\t\t\t\t\t\targuments = buffer + strlen( Cmd->Node.ln_Name );\n\n"
  185.               "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
  186.               "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
  187.               "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
  188.               "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
  189.               "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
  190.               "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
  191.               "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
  192.               "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
  193.               "\n"
  194.               "\t\t\t\t\t\tif( rdargs = ReadArgs( Cmd->Template, ArgArray, args )) {\n\n"
  195.               "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n"
  196.               "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
  197.               "\t\t\t\t\t\t} else\n"
  198.               "\t\t\t\t\t\t\tfail = TRUE;\n\n"
  199.               "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
  200.               "\t\t\t\t\t} else\n"
  201.               "\t\t\t\t\t\tfail = TRUE;\n\n"
  202.               "\t\t\t\t} else\n"
  203.               "\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n\n"
  204.               "\t\t\t} else {\n\n"
  205.               "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
  206.               "\t\t\t\t\tfail = TRUE;\n\n"
  207.               "\t\t\t};\n\n"
  208.               "\t\t\tif( fail )\n"
  209.               "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
  210.               "\t\t\tif( found )\n"
  211.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
  212.               "\t\t}\n"
  213.               "\t}\n"
  214.               "}\n";
  215.  
  216.  
  217. static UBYTE   ARexxCode[] = "\nBOOL SetupRexxPort( void )\n"
  218.               "{\n"
  219.               "\tUWORD\t\tcnt = 0;\n"
  220.               "\n"
  221.               "\tForbid();\n"
  222.               "\n"
  223.               "\tdo {\n"
  224.               "\t\tcnt += 1;\n"
  225.               "\t\tsprintf( RexxPortName, RexxPort_fmt, cnt );\n"
  226.               "\t} while( FindPort( RexxPortName ));\n"
  227.               "\n"
  228.               "\tRexxPort = CreateMsgPort();\n"
  229.               "\tif (!RexxPort) {\n"
  230.               "\t\tPermit();\n"
  231.               "\t\treturn( FALSE );\n"
  232.               "\t};\n"
  233.               "\n"
  234.               "\tRexxPort->mp_Node.ln_Name = RexxPortName;\n"
  235.               "\tRexxPort->mp_Node.ln_Pri  = 0;\n"
  236.               "\n"
  237.               "\tAddPort( RexxPort );\n\n"
  238.               "\tPermit();\n\n"
  239.               "\treturn( TRUE );\n"
  240.               "}\n"
  241.               "\n"
  242.               "void DeleteRexxPort( void )\n"
  243.               "{\n"
  244.               "\tAPTR\tm;\n\n"
  245.               "\tif (!RexxPort)\n"
  246.               "\t\treturn;\n"
  247.               "\n"
  248.               "\twhile( RX_Unconfirmed ) {\n"
  249.               "\t\tWaitPort( RexxPort );\n"
  250.               "\t\tHandleRexxMsg();\n"
  251.               "\t};\n"
  252.               "\n"
  253.               "\tForbid();\n"
  254.               "\tRemPort( RexxPort );\n\n"
  255.               "\twhile( m = GetMsg( RexxPort ))\n"
  256.               "\t\tReplyMsg( m );\n\n"
  257.               "\tDeleteMsgPort( RexxPort );\n"
  258.               "\tRexxPort = NULL;\n"
  259.               "\tPermit();\n"
  260.               "}\n"
  261.               "\n"
  262.               "BOOL SendRexxMsg( char *Host, char *Ext, char *Command, APTR Msg, LONG Flags )\n"
  263.               "{\n"
  264.               "\tAPTR\t\tstring;\n"
  265.               "\tstruct MsgPort\t*Port;\n"
  266.               "\tstruct RexxMsg\t*RxMsg;\n\n"
  267.               "\tif(!( RexxPort ))\n"
  268.               "\t\treturn( FALSE );\n"
  269.               "\n"
  270.               "\tif(!( RxMsg = CreateRexxMsg( RexxPort, Ext, RexxPortName )))\n"
  271.               "\t\treturn( FALSE );\n"
  272.               "\n"
  273.               "\tif(!( string = CreateArgstring( Command, strlen( Command )))) {\n"
  274.               "\t\tDeleteRexxMsg( RxMsg );\n"
  275.               "\t\treturn( FALSE );\n"
  276.               "\t};\n\n"
  277.               "\tRxMsg->rm_Args[0]  = string;\n"
  278.               "\tRxMsg->rm_Args[15] = Msg;\n"
  279.               "\tRxMsg->rm_Action   = Flags | RXCOMM;\n"
  280.               "\n"
  281.               "\tForbid();\n"
  282.               "\tif( Port = FindPort( Host ))\n"
  283.               "\t\tPutMsg( Port, ( struct Message * )RxMsg );\n"
  284.               "\tPermit();\n\n"
  285.               "\tif( Port ) {\n"
  286.               "\t\tRX_Unconfirmed += 1;\n"
  287.               "\t\treturn( TRUE );\n"
  288.               "\t} else {\n"
  289.               "\t\tDeleteArgstring( string );\n"
  290.               "\t\tDeleteRexxMsg( RxMsg );\n"
  291.               "\t\treturn( FALSE );\n"
  292.               "\t};\n"
  293.               "}\n";
  294.  
  295. ///
  296.  
  297.  
  298. /// StrToUpper
  299. void StrToUpper( STRPTR From, STRPTR To )
  300. {
  301.     UBYTE   c;
  302.  
  303.     while( c = *From++ )
  304.     *To++ = toupper( c );
  305.  
  306.     *To = '\0';
  307. }
  308. ///
  309. /// StrToLower
  310. void StrToLower( STRPTR From, STRPTR To )
  311. {
  312.     UBYTE   c;
  313.  
  314.     while( c = *From++ )
  315.     *To++ = tolower( c );
  316.  
  317.     *To = '\0';
  318. }
  319. ///
  320.  
  321. //  ***  Main Routines  ***
  322. /// OpenFiles
  323. struct GenFiles *OpenFiles( __A0 struct IE_Data *IE, __A1 UBYTE *BaseName )
  324. {
  325.     UBYTE               buffer[1024], buffer2[1024];
  326.     UBYTE              *ptr, *ptr2, *ptr3;
  327.     struct GenFiles    *Files;
  328.  
  329.     if(!( Files = AllocMem( sizeof( struct GenFiles ), MEMF_CLEAR )))
  330.     return( NULL );
  331.  
  332.     ptr2 = FilePart( BaseName );
  333.  
  334.     ptr  = BaseName;
  335.     ptr3 = buffer;
  336.     while( ptr != ptr2 )
  337.     *ptr3++ = *ptr++;
  338.  
  339.     *ptr3 = '\0';
  340.  
  341.     ptr = buffer2;
  342.     while(( *ptr2 != '.' ) && ( *ptr2 ))
  343.     *ptr++ = *ptr2++;
  344.     *ptr = '\0';
  345.  
  346.     AddPart( buffer, buffer2, 1024 );
  347.  
  348.     strcpy( buffer2, buffer );
  349.     strcat( buffer2, ".e" );
  350.  
  351.     if(!( Files->Std = Open( buffer2, MODE_NEWFILE )))
  352.     return( NULL );
  353.  
  354.  
  355.     if( IE->C_Prefs & GEN_TEMPLATE ) {
  356.  
  357.     strcpy( buffer2, buffer );
  358.     strcat( buffer2, "_temp.e" );
  359.  
  360.     if(!( Files->Temp = Open( buffer2, MODE_NEWFILE )))
  361.         goto error;
  362.  
  363.     }
  364.  
  365.     if( IE->SrcFlags & MAINPROC ) {
  366.  
  367.     strcpy( buffer2, buffer );
  368.     strcat( buffer2, "Main.e" );
  369.  
  370.     if( AskFile( buffer2, IE ))
  371.         if(!( Files->Main = Open( buffer2, MODE_NEWFILE )))
  372.         goto error;
  373.     }
  374.  
  375.     if( IE->SrcFlags & LOCALIZE ) {
  376.  
  377.     IE->C_Prefs |= SMART_STR;
  378.  
  379.     strcpy( buffer2, buffer );  // get the right dir
  380.     *( FilePart( buffer2 )) = '\0';
  381.  
  382.     strcat( buffer2, IE->Locale->Catalog );
  383.     strcat( buffer2, ".cd" );
  384.  
  385.     if( AskFile( buffer2, IE ))
  386.         if(!( (BPTR)Files->User1 = Open( buffer2, MODE_NEWFILE )))
  387.         goto error;
  388.  
  389.     FPrintf(( BPTR )Files->User1, ";\n"
  390.                       ";    Source code created by Interface Editor\n"
  391.                       ";    Copyright © 1994-1996 by Simone Tellini\n;\n"
  392.                       ";    Generator:  %s;\n"
  393.                       ";    Copy registered to :  %s\n"
  394.                       ";    Serial Number      : #%ld\n"
  395.                       ";\n",
  396.          LibId, IE->User->Name, IE->User->Number );
  397.  
  398.     if( IE->Locale->JoinFile[0] ) {
  399.  
  400.         BPTR lock;
  401.  
  402.         if(!( lock = Lock( IE->Locale->JoinFile, ACCESS_READ ))) {
  403.  
  404.         ULONG tags[] = { RT_ReqPos, REQPOS_CENTERSCR, RT_Underscore, '_',
  405.                  RT_Screen, IE->ScreenData->Screen, TAG_DONE };
  406.  
  407.         UBYTE fault[80];
  408.  
  409.         Fault( ERROR_OBJECT_NOT_FOUND, NULL, fault, 80 );
  410.  
  411.         rtEZRequest( "%s:\n%s.", "_Oops...",
  412.                  NULL, (struct TagItem *)tags,
  413.                  IE->Locale->JoinFile, fault );
  414.         } else {
  415.         APTR                    copy;
  416.         BPTR                    join;
  417.         struct FileInfoBlock    fib;
  418.  
  419.         Examine( lock, &fib );
  420.  
  421.         UnLock( lock );
  422.  
  423.         if(!( join = Open( IE->Locale->JoinFile, MODE_OLDFILE )))
  424.             goto error;
  425.  
  426.         if(!( copy = AllocMem( fib.fib_Size, 0L )))
  427.             goto error;
  428.  
  429.         Read( join, copy, fib.fib_Size );
  430.         Close( join );
  431.  
  432.         Flush(( BPTR )Files->User1 );
  433.         Write(( BPTR )Files->User1, copy, fib.fib_Size );
  434.  
  435.         FreeMem( copy, fib.fib_Size );
  436.         }
  437.     }
  438.  
  439.     Files->User3 = IE;
  440.     }
  441.  
  442.     NewList(( struct List *)&Files->Strings );
  443.     NewList(( struct List *)&Files->Arrays  );
  444.  
  445.     if( IE->C_Prefs & SMART_STR )
  446.     if(!( ProcessStrings( IE, Files )))
  447.         goto error;
  448.  
  449.     return( Files );
  450.  
  451.  
  452. error:
  453.  
  454.     CloseFiles( Files );
  455.  
  456.     return( NULL );
  457. }
  458. ///
  459. /// CloseFiles
  460. void CloseFiles( __A0 struct GenFiles *Files )
  461. {
  462.     UBYTE   buffer[256];
  463.  
  464.     if( Files ) {
  465.     if( Files->Std   )  Close( Files->Std   );
  466.     if( Files->Temp  )  Close( Files->Temp  );
  467.     if( Files->Main  )  Close( Files->Main  );
  468.  
  469.     if( Files->User1 ) {
  470.         UBYTE  *from, *to, *ptr;
  471.         UBYTE   command[ 1024 ];
  472.  
  473.         strcpy( command, "CatComp \"" );
  474.  
  475.         from = Files->XDefName;
  476.         to = FilePart( Files->XDefName );
  477.         ptr = buffer;
  478.         while( from < to )
  479.         *ptr++ = *from++;
  480.         *ptr = '\0';
  481.  
  482.         strcat( command, buffer );
  483.         strcat( command, ((struct IE_Data *)Files->User3 )->Locale->Catalog );
  484.         strcat( command, ".cd\" CTFILE \"" );
  485.         strcat( command, buffer );
  486.         strcat( command, ((struct IE_Data *)Files->User3 )->Locale->Catalog );
  487.         strcat( command, ".ct\" CFILE \"" );
  488.         strcat( command, buffer );
  489.  
  490.         ptr = command;
  491.         while( *ptr++ );
  492.         ptr -= 1;
  493.  
  494.         while( *to != '.' )
  495.         *ptr++ = *to++;
  496.         *ptr = '\0';
  497.  
  498.         strcat( command, "_Locale.h\"" );
  499.  
  500.         Close( (BPTR)Files->User1 );
  501.  
  502.         SystemTagList( command, NULL );
  503.     }
  504.  
  505.     FreeStrings( Files );
  506.  
  507.     FreeMem( Files, sizeof( struct GenFiles ));
  508.     }
  509. }
  510. ///
  511.  
  512. /// WriteHeaders
  513. BOOL WriteHeaders( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  514. {
  515.     struct WindowInfo  *wnd;
  516.     struct GadgetInfo  *gad;
  517.     ULONG               cnt;
  518.  
  519.     FPrintf( Files->Std,  Header, LibId, IE->User->Name, IE->User->Number );
  520.     FPrintf( Files->XDef, Header, LibId, IE->User->Name, IE->User->Number );
  521.  
  522.     if( Files->Temp ) {
  523.     FPrintf( Files->Temp, Header, LibId, IE->User->Name, IE->User->Number );
  524.  
  525.     FPuts( Files->Temp,
  526.         "/*\n"
  527.         "   In this file you'll find empty  template  routines\n"
  528.         "   referenced in the GUI source.  You  can fill these\n"
  529.         "   routines with your code or use them as a reference\n"
  530.         "   to create your main program.\n"
  531.         "*/\n\n" );
  532.     }
  533.  
  534.     if( Files->Main ) {
  535.     FPrintf( Files->Main, Header, LibId, IE->User->Name, IE->User->Number );
  536.     WriteMain( Files, IE );
  537.     }
  538.  
  539.     FPuts( Files->Std, "MODULE 'exec/nodes', 'intuition/intuition', 'intuition/gadgetclass.h', 'libraries/gadtools'\n\n" );
  540.  
  541.     if( IE->SrcFlags & OPENDISKFONT )
  542.     FPuts( Files->Std, "MODULE 'diskfont'\n\n" );
  543.  
  544.     if( IE->NumRexxs )
  545.     FPuts( Files->Std, "MODULE 'rexx/rxslib', 'rexx/rexxio', 'rexx/errors', 'rexx/storage'\n"
  546.                "MODULE 'dos/dos', 'dos/rdargs'\n\n" );
  547.  
  548.     if( IE->SrcFlags & LOCALIZE )
  549.     FPuts( Files->Std, "MODULE 'libraries/locale'\n\n" );
  550.  
  551.  
  552. //    FPrintf( Files->Std, "MODULE \"%s\"\n\n", FilePart( Files->XDefName ));
  553.  
  554.  
  555.     FPuts( Files->XDef, "CONST WT_LEFT=0, WT_TOP=1, WT_WIDTH=2, WT_HEIGHT=3\n\n" );
  556.  
  557.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  558.     struct GadgetBank  *bank;
  559.  
  560.     cnt = 0;
  561.     for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  562.         if( gad->g_Kind < MIN_IEX_ID ) {
  563.         TEXT    Label[60];
  564.  
  565.         StrToUpper( gad->g_Label, Label );
  566.  
  567.         FPrintf( Files->XDef, "CONST GD_%s=%ld\n", Label, cnt );
  568.         cnt += 1;
  569.         }
  570.  
  571.  
  572.     for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ )
  573.         for( gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  574.         if( gad->g_Kind < MIN_IEX_ID ) {
  575.             TEXT    Label[60];
  576.  
  577.             StrToUpper( gad->g_Label, Label );
  578.  
  579.             FPrintf( Files->XDef, "CONST GD_%s=%ld\n", Label, cnt );
  580.             cnt += 1;
  581.         }
  582.  
  583.  
  584.     if( cnt )
  585.         FPutC( Files->XDef, 10 );
  586.     }
  587.  
  588.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  589.     struct GadgetBank  *bank;
  590.  
  591.     cnt = wnd->wi_NumGads - wnd->wi_NumBools;
  592.  
  593.     if( cnt ) {
  594.         TEXT    Label[60];
  595.  
  596.         StrToUpper( wnd->wi_Label, Label );
  597.  
  598.         FPrintf( Files->XDef, "CONST %s_CNT=%ld\n", Label, cnt );
  599.     }
  600.  
  601.     for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ ) {
  602.         struct GadgetInfo  *gad;
  603.  
  604.         for( cnt = 0, gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  605.         if( gad->g_Kind < BOOLEAN )
  606.             cnt += 1;
  607.  
  608.         if( cnt ) {
  609.         TEXT    Label[60];
  610.  
  611.         StrToUpper( bank->Label, Label );
  612.  
  613.         FPrintf( Files->XDef, "CONST %s_CNT=%ld\n", Label, cnt );
  614.         }
  615.     }
  616.     }
  617.  
  618.     FPutC( Files->XDef, 10 );
  619.  
  620.     ( *IE->IEXSrcFun->Headers )( Files );
  621.  
  622.     return( TRUE );
  623. }
  624. ///
  625. /// WriteVars
  626. BOOL WriteVars( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  627. {
  628.     int                 cnt;
  629.     struct WindowInfo  *wnd;
  630.  
  631.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  632.     if( wnd->wi_NumGBanks ) {
  633.  
  634.         FPuts( Files->XDef, "OBJECT windowbanks\n"
  635.                 "    banks:PTR TO PTR TO gadget\n"
  636.                 "    count:INT\n"
  637.                 "ENDOBJECT\n\n" );
  638.         break;
  639.     }
  640.  
  641.     FPuts( Files->Std, "DEF visualinfo, yoffset, xoffset, scr=NIL:PTR TO screen\n" );
  642.  
  643.     if( IE->SrcFlags & FONTSENSITIVE )
  644.     FPuts( Files->Std, "DEF font:PTR TO textattr, attr:textattr, fontx, fonty\n" );
  645.  
  646.     if(!( IE->flags_2 & GENERASCR )) {
  647.     FPuts( Files->Std,  "DEF pubscreenname=NIL:PTR TO CHAR\n" );
  648.     } else {
  649.     if( IE->ScreenData->ScrAttrs & SC_ERRORCODE ) {
  650.         FPuts( Files->Std,  "DEF screenerror=NIL\n" );
  651.     }
  652.     }
  653.  
  654.     if( IE->SrcFlags & LOCALIZE ) {
  655.     FPrintf( Files->Std, "DEF localized[%ld]:ARRAY OF CHAR, catalog=NIL:PTR TO catalog\n",
  656.          IE->num_win );
  657.     }
  658.  
  659.     if( IE->NumRexxs ) {
  660.     FPrintf( Files->Std, "DEF rx_unconfirmed, rexxport:PTR TO msgport,\n"
  661.                  "    rexxportname[%ld]:STRING\n"
  662.                  "CONST REXX_EXT='%s'\n",
  663.          strlen( IE->RexxPortName ) + 4,
  664.          IE->RexxExt );
  665.     }
  666.  
  667.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  668.     TEXT    Label[60];
  669.  
  670.     StrToLower( wnd->wi_Label, Label );
  671.  
  672.     FPrintf( Files->Std,  "DEF %swnd=NIL:PTR TO window\n", Label );
  673.     }
  674.  
  675.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  676.     if( wnd->wi_NumMenus ) {
  677.         TEXT    Label[60];
  678.  
  679.         StrToLower( wnd->wi_Label, Label );
  680.  
  681.         FPrintf( Files->Std,  "DEF %smenus=NIL:PTR TO menu\n", Label );
  682.     }
  683.     }
  684.  
  685.  
  686.     //      Gadget Lists
  687.  
  688.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  689.     if( wnd->wi_NumGads - wnd->wi_NumBools ) {
  690.         TEXT    Label[60];
  691.  
  692.         StrToLower( wnd->wi_Label, Label );
  693.  
  694.         FPrintf( Files->Std,  "DEF %sglist=NIL:PTR TO gadget\n", Label );
  695.     }
  696.     }
  697.  
  698.  
  699.     //      Gadget Banks
  700.  
  701.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  702.     if( wnd->wi_NumGBanks ) {
  703.         struct GadgetBank  *bank;
  704.         TEXT    Label[60];
  705.  
  706.         StrToLower( wnd->wi_Label, Label );
  707.  
  708.         FPrintf( Files->Std,  "DEF %sgbanks[%ld]:ARRAY OF PTR TO gadget,\n"
  709.                   "    %swbanks=[ {%sgbanks}, 0 ]:windowbanks\n",
  710.                   Label, wnd->wi_NumGBanks,
  711.                   Label, Label );
  712.  
  713.         for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ ) {
  714.         struct GadgetInfo  *gad;
  715.         ULONG               count = 0;
  716.  
  717.         for( gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  718.             if( gad->g_Kind < BOOLEAN )
  719.             count += 1;
  720.  
  721.         if( count ) {
  722.             TEXT    Label[60];
  723.  
  724.             StrToLower( bank->Label, Label );
  725.  
  726.             FPrintf( Files->Std,  "DEF %sglist=NIL:PTR TO gadget,\n"
  727.                       "    %sgadgets[%ld]:ARRAY OF PTR TO gadget\n",
  728.                       Label, Label, count );
  729.         }
  730.         }
  731.     }
  732.     }
  733.  
  734.  
  735.     //      IntuiMessages
  736.  
  737.     if( IE->C_Prefs & INTUIMSG ) {
  738.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  739.         if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))) {
  740.         TEXT    Label[60];
  741.  
  742.         StrToLower( wnd->wi_Label, Label );
  743.         FPrintf( Files->Std,  "DEF %smsg:intuimessage\n", Label );
  744.         }
  745.     }
  746.     }
  747.  
  748.  
  749.  
  750.     //      Gadget Pointers Arrays
  751.  
  752.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  753.     cnt = wnd->wi_NumGads - wnd->wi_NumBools;
  754.     if( cnt ) {
  755.         TEXT    Label[60];
  756.  
  757.         StrToLower( wnd->wi_Label, Label );
  758.         FPrintf( Files->Std,  "DEF %sgadgets[%ld]:ARRAY OF PTR TO gadget\n", Label, cnt );
  759.     }
  760.     }
  761.  
  762.  
  763.     if( IE->SrcFlags & SHARED_PORT ) {
  764.  
  765.     Files->User2 = IE->SharedPort[0] ? (APTR)&IE->SharedPort[0] : (APTR)"idcmpport";
  766.  
  767.     StrToLower( Files->User2, Files->User2 );
  768.  
  769.     if(!( IE->SharedPort[0] ))
  770.         FPuts( Files->Std, "DEF idcmpport:PTR TO msgport\n" );
  771.  
  772.     FPuts( Files->Std, "DEF idcmpmsg:intuimessage\n" );
  773.     }
  774.  
  775.  
  776.     // Expanders
  777.     ( *IE->IEXSrcFun->Globals )( Files );
  778.  
  779.     if( IE->SrcFlags & OPENDISKFONT )
  780.     WriteFontPtrs( Files, IE );
  781.  
  782.     return( TRUE );
  783. }
  784. ///
  785. /// WriteData
  786. BOOL WriteData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  787. {
  788.     struct WindowInfo  *wnd;
  789.  
  790.     // Gadget Labels
  791.  
  792.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  793.     WriteGLabels( Files, IE, &wnd->wi_Gadgets, wnd );
  794.  
  795.  
  796.     // Gadget Types
  797.  
  798.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  799.     if( wnd->wi_NumGads - wnd->wi_NumBools ) {
  800.         TEXT    Label[60];
  801.  
  802.         StrToLower( wnd->wi_Label, Label );
  803.  
  804.         FPrintf( Files->Std, "\nDEF %sgtypes = [\n\t", Label );
  805.  
  806.         WriteGTypes( Files, IE, &wnd->wi_Gadgets );
  807.     }
  808.     }
  809.  
  810.     // Fonts
  811.  
  812.     struct TxtAttrNode *fnt;
  813.     for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
  814.     TEXT    Label[60];
  815.  
  816.     StrToLower( fnt->txa_Label, Label );
  817.  
  818.     FPrintf( Files->Std, "\nDEF %s = [ '%s', %ld, $%lx, $%lx ]:textattr\n",
  819.          Label, fnt->txa_FontName, fnt->txa_Size,
  820.          fnt->txa_Style, fnt->txa_Flags );
  821.     }
  822.  
  823.  
  824.     // NewGadget structures
  825.     WriteNewGadgets( Files, IE );
  826.  
  827.     // Gadget Tags
  828.     WriteGadgetTags( Files, IE );
  829.  
  830.     // Boolean Structures
  831.     WriteBoolStruct( Files, IE );
  832.  
  833.     // Gadget Banks Data
  834.     WriteGadgetBanks( Files, IE );
  835.  
  836.     // Expanders
  837.     ( *IE->IEXSrcFun->Data )( Files );
  838.  
  839.     // Menus
  840.     WriteMenuStruct( Files, IE );
  841.  
  842.     // IntuiTexts
  843.     WriteITexts( Files, IE );
  844.  
  845.     // Images (used by the GUI)
  846.     WriteImgStruct( Files, IE );
  847.  
  848.     // Images (in windows)
  849.     WriteImageStruct( Files, IE );
  850.  
  851.     // Rexx Commands
  852.     WriteRexxCmds( Files, IE );
  853.  
  854.     // Windows' Zoom
  855.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  856.     if( wnd->wi_Tags & W_ZOOM ) {
  857.         TEXT    Label[60];
  858.  
  859.         StrToLower( wnd->wi_Label, Label );
  860.  
  861.         FPrintf( Files->Std, "\nDEF %szoom = [ ", Label );
  862.         VFPrintf( Files->Std, "%d, %d, %d, %d ]:INT;\n", &wnd->wi_ZLeft );
  863.     }
  864.     }
  865.  
  866.     // Windows Tags
  867.     WriteWindowTags( Files, IE );
  868.  
  869.     // Screen Tags
  870.     if( IE->flags_2 & GENERASCR )
  871.     WriteScreenTags( Files, IE );
  872.  
  873.     return( TRUE );
  874. }
  875. ///
  876. /// WriteChipData
  877. BOOL WriteChipData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  878. {
  879.     struct ImageNode   *img;
  880.     UWORD               words, num, *ptr;
  881.  
  882.     for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {
  883.     if( img->in_Size ) {
  884.  
  885.         words = img->in_Size >> 1;
  886.  
  887.         FPrintf( Files->Std, "\n%s %sImgData[%ld] = {\n\t",
  888.              IE->ChipString, img->in_Label, words );
  889.  
  890.         FPrintf( Files->XDef, "extern %s %sImgData[%ld];\n",
  891.              IE->ChipString, img->in_Label, words );
  892.  
  893.         ptr = img->in_Data;
  894.  
  895.         num = 8;
  896.         do {
  897.  
  898.         FPrintf( Files->Std, "0x%04lx", *ptr++ );
  899.  
  900.         num   -= 1;
  901.         words -= 1;
  902.  
  903.         if( words ) {
  904.  
  905.             FPutC( Files->Std, ',' );
  906.  
  907.             if(!( num )) {
  908.             FPuts( Files->Std, "\n\t" );
  909.             num = 8;
  910.             }
  911.         }
  912.  
  913.         } while( words );
  914.  
  915.         FPuts( Files->Std, "\n};\n" );
  916.  
  917.     }
  918.     }
  919.  
  920.     // Expanders
  921.     ( *IE->IEXSrcFun->ChipData )( Files );
  922.  
  923.     return( TRUE );
  924. }
  925. ///
  926. /// WriteCode
  927. BOOL WriteCode( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  928. {
  929.  
  930.     // Expanders
  931.     ( *IE->IEXSrcFun->Support )( Files );
  932.  
  933.     if( IE->SrcFlags & SHARED_PORT )
  934.     WriteOpenWndShd( Files, IE );
  935.  
  936.     if( IE->SrcFlags & LOCALIZE )
  937.     WriteLocale( Files, IE );
  938.  
  939.     WriteSetupScr( Files, IE );
  940.  
  941.     WriteGBanksHandling( Files, IE );
  942.  
  943.     WriteOpenFonts( Files, IE );
  944.  
  945.     WriteOpenWnd( Files, IE );
  946.  
  947.     WriteRender( Files, IE );
  948.  
  949.     if( IE->NumRexxs ) {
  950.     FPuts( Files->Std, ARexxCode );
  951.  
  952.     if( IE->SrcFlags & AREXX_CMD_LIST )
  953.         FPuts( Files->Std, ARexxHandleList );
  954.     else
  955.         FPuts( Files->Std, ARexxHandleArray );
  956.     }
  957.  
  958.     if( IE->C_Prefs & IDCMP_HANDLER )
  959.     WriteIDCMPHandler( Files, IE );
  960.  
  961.     if( IE->C_Prefs & KEY_HANDLER )
  962.     WriteKeyHandler( Files, IE );
  963.  
  964.     if( IE->C_Prefs & CLICKED )
  965.     WriteClickedPtrs( Files, IE );
  966.  
  967.     return( TRUE );
  968. }
  969. ///
  970. /// WriteStrings
  971. BOOL WriteStrings( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  972. {
  973.  
  974.     if( Files->User1 ) {
  975.     WriteCD( Files );
  976.     } else {
  977.     if(( IE->C_Prefs & SMART_STR ) && (!( IE->SrcFlags & LOCALIZE ))) {
  978.  
  979.         struct StringNode  *str;
  980.  
  981.         FPutC( Files->Std, 10 );
  982.  
  983.         for( str = Files->Strings.mlh_Head; str->Next; str = str->Next ) {
  984.  
  985.         FPrintf( Files->Std, "CONST %s = '%s'\n",
  986.              str->Label, str->String );
  987.         }
  988.     }
  989.     }
  990.  
  991.     if( IE->C_Prefs & SMART_STR ) {
  992.  
  993.     struct ArrayNode   *ar;
  994.     UBYTE             **array;
  995.  
  996.     for( ar = Files->Arrays.mlh_Head; ar->Next; ar = ar->Next ) {
  997.  
  998.         FPrintf( Files->Std, "\nDEF %s = [", ar->Label );
  999.  
  1000.         array = ar->Array;
  1001.  
  1002.         while( *array ) {
  1003.         FPrintf( Files->Std, "\n\t%s,",
  1004.              ( FindString( &Files->Strings, *array ))->Label );
  1005.         array++;
  1006.         }
  1007.  
  1008.         FPuts( Files->Std, "\n\tNIL\n]:PTR TO CHAR\n" );
  1009.     }
  1010.     }
  1011.  
  1012.     return( TRUE );
  1013. }
  1014. ///
  1015.  
  1016.